package com.rabbit.mq.web;

import com.rabbit.mq.config.TopicRabbitConfig;
import com.rabbit.mq.util.MsgDataUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version V1.0.0
 * @ClassName: {@link DirectSendController}
 * @Description: SendMessageController
 * @author: Lanzhou
 * @date: 2021/3/17 9:58
 * @Copyright:2020 All rights reserved.
 */
@RestController
@RequestMapping("/direct")
public class DirectSendController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 预期结果为, 发送时 Queue01Listener Queue02Listener 度可以监听到
     * @return
     */
    @GetMapping("/sendTopic1")
    public String sendTopic1() {
        Map<String, String> map = MsgDataUtil.buildMsg();
        String messageData = "message: M A N ";
        map.put("messageData", messageData);
        rabbitTemplate.convertAndSend("exchange01", TopicRabbitConfig.F, map);
        return "{\"code\":200,\"msg\":\"SUCCESS\"}";
    }


    /**
     * 预期结果为, 发送时 Queue02Listener 才可以监听到
     * @return
     */
    @GetMapping("/sendTopic2")
    public String sendTopic2() {
        Map<String, String> map = MsgDataUtil.buildMsg();
        String messageData = "message: woman is all ";
        map.put("messageData", messageData);
        rabbitTemplate.convertAndSend("exchange01", "topic.adsfasdf", map);
        return "{\"code\":200,\"msg\":\"SUCCESS\"}";
    }





}
